<?php

namespace statistics\utils;

require_once (substr ( __DIR__, 0, strpos ( __DIR__, 'statistics' ) + 10 ) . DIRECTORY_SEPARATOR . 'includes.php');
class HTTPParameterReader {
	
	const DATATYPE_STRING = 'string';
	
	const DATATYPE_NUMERIC = 'numeric';
	
	const DATATYPE_BOOLEAN = 'boolean';
	
	const DATATYPE_HTML = 'html';
	
	const DATATYPE_DATE = 'date';
	
	const DATATYPE_FILE = 'file';
	
	private $datatypes = array (
			self::DATATYPE_STRING => 'string',
			self::DATATYPE_NUMERIC => 'numeric',
			self::DATATYPE_BOOLEAN => 'boolean',
			self::DATATYPE_HTML => 'html',
			self::DATATYPE_DATE => 'date',
			self::DATATYPE_FILE => 'file' 
	);	
	private $datatype;
	private $defaultValue;
	private $requireValue;
	private $validValues;
	private $directOutput;
	
	public function __construct() {
		$this->datatype = self::DATATYPE_STRING;
		$this->directOutput = false;
		$this->requireValue = false;
	}
	public function readGETParameter($paramName) {
		return admFuncVariableIsValid ( $_GET, $paramName, $this->datatype, $this->defaultValue, $this->requireValue, $this->validValues, $this->directOutput );
	}
	public function readPOSTParameter($paramName) {
		return admFuncVariableIsValid ( $_POST, $paramName, $this->datatype, $this->defaultValue, $this->requireValue, $this->validValues, $this->directOutput );
	}
	public function setDataType($datatype) {
		$selectedDatatype = $this->datatypes[$datatype];	
		if($selectedDatatype != null){
			$this->datatype = $selectedDatatype;	
		}
	}
	public function setValidValues(array $validValues) {
		$this->validValues = $validValues;
	}
	public function setDefaultValue($defaultValue){
		$this->defaultValue = $defaultValue;
	}
	public function setRequireValue(boolean $requireValue){
		$this->requireValue = $requireValue;
	}
	public function setDirectOutput(boolean $directOutput) {
		$this->directOutput = $directOutput;
	}
}

?>